﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HTMLDoc;

namespace GraphList
{
    public class Vertex
    {
        private HtmlDoc htmlDoc; // Contains the htmlsite as a string variable, the htmlsites url and links to other htmlsites.
        private string url;
        private bool mark;
        private ICollection<Edge> edges;

        public Vertex(HtmlDoc htmlDoc)
        {
            mark = false;
            this.htmlDoc = htmlDoc;
            this.url = htmlDoc.Url;
            edges = new LinkedList<Edge>();
        }

        // Adds an edge from this vertex to the one which is in the parameter.
        public void AddEdge(Vertex to)
        {
            Edge newEdge = new Edge(this, to);
            edges.Add(newEdge);
        }

        public ICollection<Edge> Edges
        {
            get { return edges; }
        }

        public bool Mark
        {
            get { return mark; }
            set { mark = value; }
        }

        public string Url
        {
            get { return url; }
            set { url = value; }
        }

        public HtmlDoc HtmlDoc
        {
            get { return htmlDoc; }
            set { htmlDoc = value; }
        }

        public override string ToString() //For debugging
        {
            return url + " " + Mark;
        }

        public override int GetHashCode() // god skik når man overrider Equals, da hashmap ellers kan opføre sig mærkeligt? -finn
        {
            return this.url.GetHashCode();
        }

        public override bool Equals(object obj) //Bruges for at sikre at der bliver sammenlignet rigtigt når der bruges metoden IndexOf().
        {
            Vertex other = (Vertex) obj;
            return url.Equals(other.url);
        }
    }
}
